//package com.example.xungeng2.filter;
//
//import com.alibaba.fastjson.JSON;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.util.AntPathMatcher;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//@WebFilter(urlPatterns = "/*")
//@Slf4j
//public class LoginFilter implements Filter {
//
//// 路径匹配符，类urls字符串匹配
//    public static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
//        HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
//
//        String uri = httpServletRequest.getRequestURI();
//        log.info("拦截到的请求是{}",httpServletRequest.getRequestURI());
//
//        String[] str = new String[]{
//                "/api/user/register/",
//                "/index.html",
//                "/api/user/login/",
//                "/css/**",
//                "/js/**",
//                "/favicon.ico",
//                "/images/**",
//                "/api/user/xgLogin",
//                "/api/worker/selectOneXGHistory"
//        };
//
//        boolean init = inuris(str, uri);
//        if(init){
//            filterChain.doFilter(httpServletRequest,httpServletResponse);
//            return;
//        }
//        if (httpServletRequest.getSession().getAttribute("user") != null){
//            filterChain.doFilter(httpServletRequest,httpServletResponse);
//            return;
//        }
//        httpServletResponse.getWriter().write(JSON.toJSONString("NOT LOGIN"));
//        return;
//    }
//
//
//    public boolean inuris(String[] uris,String uri){
//        for (String str : uris) {
//            boolean match = PATH_MATCHER.match(str, uri);
//            if (match){
//                return true;
//            }
//        }
//        return false;
//    }
//}